package com.demo.test.graph;

import com.alibaba.fastjson2.JSON;

public class Main {
    public static void main(String[] args) {
        // 创建图实例
        Graph graph = new Graph();

        // 创建节点
        Node nodeA = new Node("A");
        Node nodeB = new Node("B");
        Node nodeC = new Node("C");
        Node nodeD = new Node("D");

        // 添加节点到图中
        graph.addNode(nodeA);
        graph.addNode(nodeB);
        graph.addNode(nodeC);
        graph.addNode(nodeD);

        // 创建边
        graph.addEdge("A", "B");
        graph.addEdge("A", "C");
        graph.addEdge("B", "D");
        graph.addEdge("C", "D");

        // 打印图的结构
        graph.printGraph();

        Node a = graph.getNode("A");
        String jsonString = JSON.toJSONString(a);
        System.out.println(jsonString);
        Node node = JSON.parseObject(jsonString, Node.class);
        System.out.println(node);
    }
}
